package com.example.demo1;

import com.example.demo1.annotation.myspringXML;
import com.example.demo1.pojo.person;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MyXmlInject {
    public static void main(String[] args){
        ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext("META-INF/personBean.xml");
        //getbean()方法这里面的参数就是你xml文件的id值，这个方法可以由这个id找到对用注入的类对象（普通pojo类）
        person myperson = classPathXmlApplicationContext.getBean("myperson", person.class);
        System.out.println("使用spring.xml注入得到的person对象"+myperson);
        //接下来就是使用注解来代替xml文件对对象的注入
        AnnotationConfigApplicationContext applicationContext=new AnnotationConfigApplicationContext(myspringXML.class);
        Object myperson1 = applicationContext.getBean("myperson");
        System.out.println(myperson1);
    }
}
